//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.qy137.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy137.entity.Banner;
import com.qy137.vo.BannerVo;
import org.apache.commons.lang.StringUtils;
import org.qy137.dao.BannerDao;
import org.qy137.service.LunBoService;
import org.qy137.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LunBoServiceImopl implements LunBoService {
    @Autowired
    private BannerDao lunBoDao;

    public LunBoServiceImopl() {
    }

    public CommonResult getAlllubbotu(Integer page, Integer limit, BannerVo bannerVo) {
        Page<Banner> banners = new Page((long)page, (long)limit);
        QueryWrapper<Banner> wrapper = new QueryWrapper();
        wrapper.eq("is_deleted", 0);
        if (StringUtils.isNotEmpty(bannerVo.getTitle())) {
            wrapper.like("title", bannerVo.getTitle());
        }

        if (bannerVo.getIsDisable() != null) {
            wrapper.eq("is_disable", bannerVo.getIsDisable());
        }

        Page<Banner> selectPage = (Page)this.lunBoDao.selectPage(banners, wrapper);
        return selectPage.getRecords().size() > 0 ? new CommonResult(2000, "查询成功", selectPage) : new CommonResult(5000, "查询失败", (Object)null);
    }

    public CommonResult deleteBanner(BannerVo bannerVo) {
        Banner banner = new Banner();
        banner.setId(bannerVo.getId());
        banner.setIsDeleted(1);
        int i = this.lunBoDao.updateById(banner);
        return i > 0 ? new CommonResult(2000, "删除成功", (Object)null) : new CommonResult(5000, "删除失败", (Object)null);
    }

    public CommonResult updataStatus(String id, Integer isDisable) {
        Banner banner = new Banner();
        banner.setId(id);
        banner.setIsDisable(isDisable);
        int i = this.lunBoDao.updateById(banner);
        return i > 0 ? new CommonResult(2000, "修改成功", (Object)null) : new CommonResult(5000, "修改失败", (Object)null);
    }

    public CommonResult addBanner(Banner banner) {
        int i;
        if (StringUtils.isNotEmpty(banner.getId())) {
            i = this.lunBoDao.updateById(banner);
            return i > 0 ? new CommonResult(2000, "修改成功", (Object)null) : new CommonResult(5000, "修改失败", (Object)null);
        } else {
            i = this.lunBoDao.insert(banner);
            return i > 0 ? new CommonResult(2000, "添加成功", (Object)null) : new CommonResult(5000, "添加失败", (Object)null);
        }
    }
}
